﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using System;
using NJamb.Parser.SpecificationBuilders.Delta.Void;
using NJamb.Parser.Subjects.Void;
using NJamb.Specifications.Simple;
using Stile.Patterns.SelfDescribingPredicates;
#endregion

namespace NJamb.Specifications.Void
{
	public class VoidSpecification<THost> : SpecificationBase<THost, IVoidCollaboratingSubject<THost>, IEvaluation>,
		IVoidSpecification<THost>,
		IVoidCollaboratingSpecification<THost>
		where THost : class
	{
		private readonly Func<THost> _getter;

		public VoidSpecification(IVoidCollaboratingSubject<THost> collaboratingSubject,
			Func<THost> getter,
			Lazy<string> lazyReason = null,
			Func<Exception, THost, IEvaluation> exceptionFilter = null)
			: base(collaboratingSubject, lazyReason, exceptionFilter)
		{
			_getter = getter;
		}

		public IVoidDeltaSpecificationBuilder<THost> AndLater
		{
			get
			{
				RequireNotAlreadyDisposed();
				return new VoidDeltaSpecificationBuilder<THost>(this);
			}
		}

		public IVoidCollaboratingSpecification<THost> Xray
		{
			get { return this; }
		}

		protected override IEvaluation GetEvaluation(out THost subject)
		{
			subject = _getter.Invoke();
			return new Evaluation();
		}
	}
}
